//
//  AppDelegate.m
//  students
//
//  Created by 任辰东 on 2024/1/5.
//

#import "AppDelegate.h"
#import "RCDTabBarViewController.h"
#import "LoginVC.h"
#import "SJRotationManager.h"
#import "SJRotationFullscreenWindow.h"

@interface AppDelegate ()
@property (nonatomic, strong) RCDTabBarViewController *tabBar;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self setNavBarAppearence];
    //登录逻辑处理
    [self setupAppLoginControl];
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)setupAppLoginControl
{

    [RACObserve([GVUserDefaults standardUserDefaults], isLoginSuccess) subscribeNext:^(NSNumber *  _Nullable isLoginSuccess) {

        if (!isLoginSuccess.boolValue) {
            LoginVC *loginVC = [LoginVC new];
            RCDBaseNavigationController *nav = [[RCDBaseNavigationController alloc]initWithRootViewController:loginVC];
            self.window.rootViewController = nav;
        }else{
            self.tabBar = [RCDTabBarViewController new];
            self.window.rootViewController = self.tabBar;
        }

    }];
}

- (void)setNavBarAppearence
{
    // 设置是 广泛使用WRNavigationBar，还是局部使用WRNavigationBar，目前默认是广泛使用
    [WRNavigationBar wr_widely];
    [WRNavigationBar wr_setBlacklist:@[@"SpecialController",
                                       @"TZPhotoPickerController",
                                       @"TZGifPhotoPreviewController",
                                       @"TZAlbumPickerController",
                                       @"TZPhotoPreviewController",
                                       @"TZVideoPlayerController",
                                       @"FGImagePickerVC",
                                       @"TZImagePickerController"]];
    
    // 设置导航栏默认的背景颜色
    [WRNavigationBar wr_setDefaultNavBarBarTintColor:UIColorFromHex(kColorMain)];
    // 设置导航栏所有按钮的默认颜色
    [WRNavigationBar wr_setDefaultNavBarTintColor:[UIColor whiteColor]];
    // 设置导航栏标题默认颜色
    [WRNavigationBar wr_setDefaultNavBarTitleColor:[UIColor whiteColor]];
    // 统一设置状态栏样式
    [WRNavigationBar wr_setDefaultStatusBarStyle:UIStatusBarStyleLightContent];
    // 如果需要设置导航栏底部分割线隐藏，可以在这里统一设置
    [WRNavigationBar wr_setDefaultNavBarShadowImageHidden:YES];
}


- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window

{
    UIInterfaceOrientationMask mask = [SJRotationManager supportedInterfaceOrientationsForWindow:window];
//    if (mask == UIInterfaceOrientationMaskAll) {
//        if (self.allowRotation == YES) {
//            return UIInterfaceOrientationMaskLandscapeLeft;
//        }else{
//            return mask;
//        }
//    } else {
//        return mask;
//    }
    return mask;
}


@end
